package cqrtplm.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.date.DateUtil;
import com.hustcad.plm.pdm.partbom.vo.PartDetailsVO;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * BOM详情头对象 DSPF_MBOM_BOM
 *
 * @author 江小熊
 * @date 2025-10-24
 */
@Data
public class DspfMbomBomDO {
    private static final long serialVersionUID = 1L;

    /**
     * 主键id
     */
    @Excel(name = "主键id")
    private String bomid;

    /**
     * 开发令
     */
    @Excel(name = "开发令")
    private String devcode;

    /**
     * 产品型号
     */
    @Excel(name = "产品型号")
    private String producttype;

    /**
     * 裸机码
     */
    @Excel(name = "裸机码")
    private String barecode;

    /**
     * 成品码
     */
    @Excel(name = "成品码")
    private String mbomcode;

    /**
     * 引用源
     */
    @Excel(name = "引用源")
    private String copyfrom;

    /**
     * 成品码描述
     */
    @Excel(name = "成品码描述")
    private String bomdescr;

    /**
     * 状态流水
     */
    @Excel(name = "状态流水")
    private Long statusnum;

    /**
     * 版本流水
     */
    @Excel(name = "版本流水")
    private Long vernum;

    /**
     * 测试要求
     */
    @Excel(name = "测试要求")
    private String testreqid;

    /**
     * 测试要求ID
     */
    @Excel(name = "测试要求ID")
    private String testingrequirements;

    /**
     * 认证ID
     */
    @Excel(name = "认证ID")
    private String certificationid;

    /**
     * 认证
     */
    @Excel(name = "认证")
    private String certification;

    /**
     * 状态：0失效/1正常/2草稿/3审批中
     */
    @Excel(name = "状态：0失效/1正常/2草稿/3审批中")
    private Long status;

    /**
     * 流程状态：0编制中/1审核通过/2校对中/3审批中
     */
    @Excel(name = "流程状态：0编制中/1审核通过/2校对中/3审批中")
    private Long flowstatus;

    /**
     * 排序码
     */
    @Excel(name = "排序码")
    private Long fSortcode;

    /**
     * 删除标记
     */
    @Excel(name = "删除标记")
    private Long fDeletemark;

    /**
     * 有效标志
     */
    @Excel(name = "有效标志")
    private Long fEnabledmark;

    /**
     * 备注
     */
    @Excel(name = "备注")
    private String fDescription;

    /**
     * 创建日期
     */
    @Excel(name = "创建日期")
    private Date fCreatedate;

    /**
     * 创建用户主键
     */
    @Excel(name = "创建用户主键")
    private String fCreateuserid;

    /**
     * 创建用户
     */
    @Excel(name = "创建用户")
    private String fCreateusername;

    /**
     * 修改日期
     */
    @Excel(name = "修改日期")
    private String fModifydate;

    /**
     * 修改用户主键
     */
    @Excel(name = "修改用户主键")
    private String fModifyuserid;

    /**
     * 修改用户
     */
    @Excel(name = "修改用户")
    private String fModifyusername;

    /**
     * 引用源
     */
    @Excel(name = "引用源")
    private String ebomid;

    /**
     * 裸机码主键
     */
    @Excel(name = "裸机码主键")
    private String barecodedescr;

    /**
     * 临时成品码
     */
    @Excel(name = "临时成品码")
    private String tempcode;

    /**
     * 是否临时裸机码
     */
    @Excel(name = "是否临时裸机码")
    private Long istempcode;

    /**
     * 优先级1234级
     */
    @Excel(name = "优先级1234级")
    private Integer priority;

    /**
     * 订单号
     */
    @Excel(name = "订单号")
    private String ordercode;

    /**
     * 项次号
     */
    @Excel(name = "项次号")
    private String orderitem;

    /**
     * 订单提交时间
     */
    @Excel(name = "订单提交时间")
    private String orderdate;

    /**
     * 订单ID
     */
    @Excel(name = "订单ID")
    private String orderitemid;

    /**
     * 1已导入0未导入2导入失败
     */
    @Excel(name = "1已导入0未导入2导入失败")
    private Long toqadstatus;

    /**
     * 导入QAD时间
     */
    @Excel(name = "导入QAD时间")
    private String toqaddate;

    /**
     * 版本号ID
     */
    @Excel(name = "版本号ID")
    private String verid;

    /**
     * 0历史版本 1当前采用版本
     */
    @Excel(name = "0历史版本 1当前采用版本")
    private Long iscurrent;

    /**
     * 0非基础状态BOM 1基础状态BOM
     */
    @Excel(name = "0非基础状态BOM 1基础状态BOM")
    private Long isbasesatus;

    /**
     * 成品码描述ID
     */
    @Excel(name = "成品码描述ID")
    private String bomdescrids;

    /**
     * 是否是半BOM
     */
    @Excel(name = "是否是半BOM")
    private String ishalfbom;

    /**
     * 需求表主键
     */
    @Excel(name = "需求表主键")
    private String statusid;

    /**
     * 需求表编码
     */
    @Excel(name = "需求表编码")
    private String statuscode;

    /**
     * 是否需要小批
     */
    @Excel(name = "是否需要小批")
    private Integer smallbatch;

    /**
     * 越南生产
     */
    @Excel(name = "越南生产")
    private Integer isvietnameseproduction;

    /**
     * 样机
     */
    @Excel(name = "样机")
    private Integer isprototype;

    /**
     * 制定列表
     */
    @Excel(name = "制定列表")
    private String appointtbl;

    /**
     * VIN码
     */
    @Excel(name = "VIN码")
    private String vinrulecode;

    /**
     * 意见
     */
    @Excel(name = "意见")
    private String opinion;

    /**
     * 最小起订量
     */
    @Excel(name = "最小起订量")
    private Integer mintrayload;

    /**
     * 货柜
     */
    @Excel(name = "货柜")
    private String containertype;

    /**
     * 流程类型
     */
    @Excel(name = "流程类型")
    private String flowcode;

    /**
     * 通用化率
     */
    @Excel(name = "通用化率")
    private String tyhl;

    /**
     * 电气确认
     */
    @Excel(name = "电气确认")
    private Long iselectrical;

    /**
     * 客户代码
     */
    @Excel(name = "客户代码")
    private String clientcode;

    /**
     * 标贴年份
     */
    @Excel(name = "标贴年份")
    private String rznf;

    /**
     * 意见
     */
    @Excel(name = "意见")
    private String halfbomexplain;

    /**
     * 0 null 新 1老配置系统 2qad旧数据
     */
    @Excel(name = "0 null 新 1老配置系统 2qad旧数据")
    private Long isold;

    /**
     * 历史成品码
     */
    @Excel(name = "历史成品码")
    private String oldmbomcode;

    /**
     * 历史动力成品码
     */
    @Excel(name = "历史动力成品码")
    private String oldpowercode;

    /**
     * 图号认证类型
     */
    @Excel(name = "图号认证类型")
    private String backuptype;

    private String powercode;

    private Long powercodetype;

    /**
     * 是否QAD最新状态
     */
    @Excel(name = "是否QAD最新状态")
    private Long isqadnewstatus;

    /**
     * 默认桌面URL
     */
    @Excel(name = "默认桌面URL")
    private String projectid;

    private String certifactioncode;

    /**
     * 变更状态 裸机:0正常 1变更中  成品:10变更前 11变更后 12过渡期
     */
    @Excel(name = "变更状态 裸机:0正常 1变更中  成品:10变更前 11变更后 12过渡期")
    private Long modifystatus;

    private String lastmodifyid;

    /**
     * null 或0 未锁定 1编辑锁定 2设变锁定
     */
    @Excel(name = "null 或0 未锁定 1编辑锁定 2设变锁定")
    private Long lockflag;

    private String lockusername;

    private String lockuserid;

    private String locktime;

    /**
     * 外购动力 0否1是
     */
    @Excel(name = "外购动力")
    private Integer purchasedpower;

    /**
     * 产品用途
     */
    @Excel(name = "产品用途")
    private String productuse;

    private String stopuserid;

    private String stopusername;

    private String stopdate;

    /**
     * 裸机码的哈希值
     */
    @Excel(name = "裸机码的哈希值")
    private String ehashkey;

    /**
     * 销售确认事件
     */
    @Excel(name = "销售确认事件")
    private String confirmtime;

    /**
     * 动力备案机型
     */
    @Excel(name = "动力备案机型")
    private String dlrecordtype;

    /**
     * 终端备案机型
     */
    @Excel(name = "终端备案机型")
    private String zdrecordtype;

    /**
     * 1已导入0未导入2导入失败
     */
    @Excel(name = "1已导入0未导入2导入失败")
    private Long tosapstatus;

    /**
     * 导入QAD时间
     */
    @Excel(name = "导入QAD时间")
    private String tosapdate;

    /**
     * 成品码类型：终端 终端动力 单机动力
     */
    @Excel(name = "成品码类型：终端 终端动力 单机动力")
    private String finishedtype;

    private Long tempstate;

    /**
     * 是否已量产
     */
    @Excel(name = "是否已量产 ")
    private Integer hasbatched;

    /**
     * 小批数量
     */
    @Excel(name = "小批数量")
    private Integer smallbatchamount;

    /**
     * 机械环保代码
     */
    @Excel(name = "机械环保代码")
    private String jxhbcode;

    private String codegentime;

    /**
     * 托盘方式
     */
    @Excel(name = "托盘方式")
    private String traymode;

    /**
     * BOM来源
     */
    @Excel(name = "BOM来源")
    private String bomsources;

    /**
     * 成品码类别 0单机动力 1机组动力 2机组
     */
    @Excel(name = "成品码类别 0单机动力 1机组动力 2机组")
    private Long bomclass;

    /**
     * 改制 0否 1是
     */
    @Excel(name = "改制 0否 1是")
    private Integer remanufacture;

    /**
     * 验证结果
     */
    @Excel(name = "验证结果")
    private Long proofresult;

    /**
     * 验证日期
     */
    @Excel(name = "验证日期")
    private String proofdate;

    /**
     * 验证成品码
     */
    @Excel(name = "验证成品码")
    private String proofmbomcode;

    /**
     * 使用情况 1首次使用 2返单 3修改后首次
     */
    @Excel(name = "使用情况 1首次使用 2返单 3修改后首次")
    private Long usetype;

    private String proofmbomid;

    /**
     * 默认工厂
     */
    @Excel(name = "默认工厂")
    private String factory;

    /**
     * 允许跨工厂使用  0不允许 1允许
     */
    @Excel(name = "允许跨工厂使用  0不允许 1允许")
    private Long crossfactoryuse;

    /**
     * Y同意该认证年份
     */
    @Excel(name = "Y同意该认证年份")
    private String agreeacceptrznf;

    /**
     * 变更的成品码
     */
    @Excel(name = "变更的成品码")
    private String modifymbom;

    /**
     * 最后一次修改
     */
    @Excel(name = "最后一次修改")
    private String timestampstr;

    /**
     * 托盘尺寸（由状态室手动填写）
     */
    @Excel(name = "托盘尺寸")
    private String traysize;

    /**
     * 1 SAP  2 QAD   3机组QAD动力SAP   4 SAP+QAD
     */
    @Excel(name = "1 SAP  2 QAD   3机组QAD动力SAP   4 SAP+QAD")
    private Long imprtbomtype;

    /**
     * PDM开发项目
     */
    @Excel(name = "PDM开发项目")
    private String projectcode;

    /**
     * V2机型
     */
    @Excel(name = "V2机型")
    private String producttypev2;

    private String terminalorpower;

    private String ownerid;

    private String ownername;

    /**
     * 小批类型
     */
    @Excel(name = "小批类型")
    private String smallbatchtype;

    /**
     * 审批状态，初始为0，审批完成1（成品码导入SAP之后视为完成）
     */
    @Excel(name = "审批状态，初始为0，审批完成1")
    private Long approvestatus;

    /**
     * Bom等级
     */
    @Excel(name = "Bom等级")
    private String bomgrade;

    //订单等级
    private String orderLevel;
    //需小批 是/否
    private String needBatch;
    //BOM年份
    private String bomyear;
    //整托加货物尺寸
    private String cargoDimensions;
    //成品码类型//0动力/1机组/2传动
    private String otype;
    //项目开发令
    private String projectDevCode;

    public DspfMbomBomDO() {

    }

    public DspfMbomBomDO(RtCfgStatusInfoDO infoDO, String bomId) {
        this.bomid = bomId;
        this.statusid = infoDO.getStatusid();
        this.statuscode = infoDO.getStatuscode();
        this.clientcode = infoDO.getCustomecode();
        this.barecodedescr = infoDO.getEbomDescr();
        this.devcode = infoDO.getDevcode();
        this.producttypev2 = infoDO.getProducttype();//需确认
        this.dlrecordtype = infoDO.getClientrecordtype();
        this.zdrecordtype = infoDO.getZdrecordtype();
        this.barecode = infoDO.getEbomcode();
        this.testreqid = infoDO.getTestreqid();
        this.factory = infoDO.getScgc();
        this.bomyear = infoDO.getBomyear();
    }

    public DspfMbomBomDO(PartDetailsVO partDetailsVO, Map<String, List<String>> ibaAttributeMap,String bomid) {
        this.bomid = bomid;
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("productType"))){
            this.producttypev2 = ibaAttributeMap.get("productType").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("devCode"))){
            this.devcode = ibaAttributeMap.get("devCode").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00028"))){
            this.fCreatedate = DateUtil.parse(ibaAttributeMap.get("00028").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("Describe"))){
            this.bomdescr = ibaAttributeMap.get("Describe").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00020"))){
            this.mbomcode = ibaAttributeMap.get("00020").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00027"))){
            this.fCreateusername = ibaAttributeMap.get("00027").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00022"))){
            this.oldmbomcode = ibaAttributeMap.get("00022").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("NeedBatch"))){
            this.smallbatch = Integer.valueOf(ibaAttributeMap.get("NeedBatch").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("smallBatchQuantity"))){
            this.smallbatchamount = Integer.valueOf(ibaAttributeMap.get("smallBatchQuantity").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("CertificationRequire"))){
            this.certification = ibaAttributeMap.get("CertificationRequire").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("CustomerCode"))){
            this.clientcode = ibaAttributeMap.get("CustomerCode").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("application"))){
            this.productuse = ibaAttributeMap.get("application").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("factory"))){
            this.factory = ibaAttributeMap.get("factory").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("developmentProject"))){
            this.projectcode = ibaAttributeMap.get("developmentProject").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00035"))){
            this.testingrequirements = ibaAttributeMap.get("00035").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00033"))){
            this.statusid = ibaAttributeMap.get("00033").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00036"))){
            this.certificationid = ibaAttributeMap.get("00036").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00026"))){
            this.bomdescr = ibaAttributeMap.get("00026").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("MOQ1"))){
            this.mintrayload = Integer.valueOf(ibaAttributeMap.get("MOQ1").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("HalfBOM"))){
            this.ishalfbom = ibaAttributeMap.get("HalfBOM").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("00023"))){
            this.tempcode = ibaAttributeMap.get("00023").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("ModelMachine"))){
            this.isprototype = Integer.valueOf(ibaAttributeMap.get("ModelMachine").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("EBOMCode"))){
            this.barecode = ibaAttributeMap.get("EBOMCode").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("TestRequire"))){
            this.testreqid = ibaAttributeMap.get("TestRequire").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("RecommendLevel"))){
            this.priority = Integer.valueOf(ibaAttributeMap.get("RecommendLevel").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("AgreeCretiYear"))){
            this.agreeacceptrznf = ibaAttributeMap.get("AgreeCretiYear").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("StatusRequireCode"))){
            this.statuscode = ibaAttributeMap.get("StatusRequireCode").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("PurchasedPower"))){
            this.purchasedpower = Integer.valueOf(ibaAttributeMap.get("PurchasedPower").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("VerifyProductCode"))){
            this.proofmbomcode = ibaAttributeMap.get("VerifyProductCode").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("PowerRegistrationModel"))){
            this.dlrecordtype = ibaAttributeMap.get("PowerRegistrationModel").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("reform"))){
            this.remanufacture = Integer.valueOf(ibaAttributeMap.get("reform").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("AlreadyMassProduced"))){
            this.hasbatched = Integer.valueOf(ibaAttributeMap.get("AlreadyMassProduced").get(0));
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("MechanicalEnvirCode"))){
            this.jxhbcode = ibaAttributeMap.get("MechanicalEnvirCode").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("OverallGoodsPallet"))){
            this.cargoDimensions = ibaAttributeMap.get("OverallGoodsPallet").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("TrayMethod"))){
            this.traymode = ibaAttributeMap.get("TrayMethod").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("TerminalRegistrationModel"))){
            this.zdrecordtype = ibaAttributeMap.get("TerminalRegistrationModel").get(0);
        }
        if(IterUtil.isNotEmpty(ibaAttributeMap.get("MadeVietnam"))){
            this.isvietnameseproduction = Integer.valueOf(ibaAttributeMap.get("MadeVietnam").get(0));
        }



    }


    public DspfMbomBomDO(PartDetailsVO partDetailsVO, Map<String, List<String>> ibaAttributeMap,RtCfgStatusInfoDO infoDO) {
        this.statusid = infoDO.getStatusid();
        this.statuscode = infoDO.getStatuscode();
        this.clientcode = infoDO.getCustomecode();
        this.barecodedescr = infoDO.getEbomDescr();
        this.dlrecordtype = infoDO.getClientrecordtype();
        this.zdrecordtype = infoDO.getZdrecordtype();
        this.barecode = infoDO.getEbomcode();
        this.testreqid = infoDO.getTestreqid();
        this.factory = infoDO.getScgc();
        this.bomyear = infoDO.getBomyear();
        this.fCreatedate = new Date();
        this.devcode = ibaAttributeMap.get("devCode")==null?"":ibaAttributeMap.get("devCode").get(0).toString();
        this.producttypev2 = ibaAttributeMap.get("productType")==null?"":ibaAttributeMap.get("productType").get(0).toString();

    }


}
